//
//  ViewController.m
//  26-Masonry代码约束
//
//  Created by mafeng on 16/8/18.
//  Copyright © 2016年 mafeng. All rights reserved.
//

#import "ViewController.h"
#import "Masonry.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    // 1.使用Masonry, 不用给初始frame
    UIView *view = [UIView new];
    // 添加约束前, 需要把视图添加到父视图, 这样添加约束才有参考
    [self.view addSubview:view];
    view.backgroundColor = [UIColor redColor];
    
    // 设置该视图约束
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
    
    // 添加蓝色视图
    UIView *blueView = [UIView new];
    blueView.backgroundColor = [UIColor blueColor];
    [self.view addSubview:blueView];
    [blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(self.view.mas_width).multipliedBy(0.5f);
        make.height.mas_equalTo(self.view.mas_height).multipliedBy(0.333f);
        // 居中
        make.center.mas_equalTo(0);

    }];
    
    // 绿色的view
    UIView *greenView = [UIView new];
    greenView.backgroundColor = [UIColor greenColor];
    [self.view addSubview:greenView];
    [greenView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.centerX.height.mas_equalTo(blueView);
        make.top.mas_equalTo(blueView.mas_bottom).mas_offset(10);
    }];
    
    [NSLayoutConstraint constraintWithItem:greenView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:blueView attribute:NSLayoutAttributeLeft multiplier:1 constant:10];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
